﻿using UnityEngine;

namespace Framework
{

    public class UIForm : MonoBehaviour, IUIForm
    {
        public string UIFormAssetName { get; }
        public UIFormLogic uiFormLogic{ get; set; }
        public object m_userData;
        public IUIGroup UIGroup { get; set; }
        
        public int SerialId { get; set; }
        public int DepthInUIGroup { get; }
        public object Handle { get; set; }
        public void OnInit(int serialId, string uiFormAssetName, IUIGroup uiGroup, bool pauseCoveredUIForm, bool isNewInstance,
            object userData)
        {
            SerialId = serialId;
            UIGroup = uiGroup;
            Handle = gameObject;
            m_userData = userData;
            uiFormLogic = GetComponent<UIFormLogic>();

            if (uiFormLogic != null)
            {
                uiFormLogic.UIForm = this;
            }
            if (isNewInstance)
            {
                uiFormLogic?.OnInit(m_userData);
            }
           
        }

        public void OnOpen(object userData)
        {
            uiFormLogic?.OnOpen(m_userData);
        }



        public void OnClose(object userData)
        {
            uiFormLogic?.OnClose(m_userData);
        }

        public void OnRecycle()
        {
            uiFormLogic?.OnRecycle(m_userData);
        }

        public void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            uiFormLogic?.OnUpdate( elapseSeconds,  realElapseSeconds,m_userData);
        }

        public void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
        {
            uiFormLogic?.OnDepthChanged(uiGroupDepth,depthInUIGroup);
        }
    }

}